package com.example.performance.jol.official;

import org.openjdk.jol.info.ClassLayout;
import org.openjdk.jol.vm.VM;

/**
 * @author Aleksey Shipilev
 */
@SuppressWarnings({"java:S101", "java:S106", "unused"})
public class JOLSample_05_SuperGaps {

    /*
     * This example shows the HotSpot field layout quirk.
     * (Works best with 64-bit VMs)
     *
     * Prior to JDK 15, even though we have the alignment gap before
     * A.a field, HotSpot does not claim it, because it does not track
     * the gaps in the already laid out superclasses.
     *
     * In JDK 15 and later, the superclass gaps are no longer present.
     *
     * See also:
     *    https://bugs.openjdk.java.net/browse/JDK-8237767
     */

    public static void main(String[] args) {
        System.out.println(VM.current().details());

        System.out.println(ClassLayout.parseClass(A.class).toPrintable());
        System.out.println(ClassLayout.parseClass(B.class).toPrintable());
        System.out.println(ClassLayout.parseClass(C.class).toPrintable());
    }

    public static class A {
        long fieldA;
    }

    public static class B extends A {
        long fieldB;
    }

    public static class C extends B {
        long fieldC;
        int fieldD;
    }

}